import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { Logger } from '../common/Logger'
import router from '@ohos.router';

export default class EntryAbility extends UIAbility {
  onCreate(want, launchParam) {
    Logger.info('Ability onCreate');
    Logger.info('want param:' + JSON.stringify(want) ?? '')
    Logger.info('launchParam:' + JSON.stringify(launchParam) ?? '')
  }

  onForeground() {
    Logger.info('Ability onForeground');
  }

  onBackground() {
    Logger.info('Ability onBackground');
  }

  onDestroy() {
    Logger.info('Ability onDestroy');
  }

  onWindowStageCreate(windowStage: window.WindowStage) {
    Logger.info('Ability onWindowStageCreate');
    //pages/SplashPage
    windowStage.loadContent('pages/MainPage', (err, data) => {
      if (err.code) {
        Logger.error('Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
        return;
      }
      Logger.info('Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
      //this.loadMainPage();
    });
  }

  onWindowStageDestroy() {
    Logger.info('%{public}s', 'Ability onWindowStageDestroy');
  }

  loadMainPage() {
    setTimeout(() => {
      router.replaceUrl({ url: "pages/MainPage" })
    }, 2 * 1000)
  }
}
